﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Publicuse.Entity.AttributeUtil.Validate
{
    /// <summary>
    /// 正整数校验
    /// </summary>
    public class PositiveintegerAttribute : BaseValidateAttribute
    {
        private int _iMin = 0;
        private int _iMax = 0;
        private string remark = null;
        public string GetRemark { get { return this.remark; } }

        /// <summary>
        /// 正整数区间校验
        /// </summary>
        /// <param name="min">包含</param>
        /// <param name="max">不包含</param>
        public PositiveintegerAttribute(int min, int max, string remark)
        {
            this._iMin = min;
            this._iMax = max;
            this.remark = remark;
        }


        public override bool Validate(object oValue)
        {
            if (oValue != null && !string.IsNullOrEmpty(oValue.ToString()))
            {
                var inpuvalue = oValue.ToString();
                if (inpuvalue.Split('.').Length >= 2)
                {
                    return false;
                }
                else
                {
                    if (Convert.ToInt32(inpuvalue) < this._iMin || Convert.ToInt32(inpuvalue) > this._iMax)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }
            else
            {
                return true;
            }
                 
        }
    }
}
